<?php

declare(strict_types=1);

namespace DreamCat\Array2Class\TestCases;

use DreamCat\Array2Class\Array2ClassConverter;
use DreamCat\Array2Class\Demo\NameChangePojo;
use DreamCat\Array2Class\TransImpl\CamelCase2UnderLine;
use DreamCat\Array2Class\TransImpl\UnderLine2CamelCase;
use PHPUnit\Framework\TestCase;

/**
 * 自动属性名转换测试
 * @author vijay
 */
class AutoTranTest extends TestCase
{
    /**
     * 测试下划线转驼峰
     * @return void
     */
    public function testUnder2Camel(): void
    {
        $convert = new Array2ClassConverter();
        $trans = new UnderLine2CamelCase();
        $convert->setPropertyNameTrans($trans);
        self::assertEquals(spl_object_id($trans), spl_object_id($convert->getPropertyNameTrans()));
        $data = [
            "camelMeta" => "534",
            "keyWordLog" => "7784jdr",
        ];
        $expect = NameChangePojo::builder(
            [
                "camelMeta" => $data["camelMeta"],
                "key_word_log" => $data["keyWordLog"],
            ]
        );
        $result = $convert->convert($data, NameChangePojo::class);
        self::assertEquals($expect, $result);
    }

    /**
     * 测试下划线转驼峰
     * @return void
     */
    public function testCamel2Under(): void
    {
        $convert = new Array2ClassConverter();
        $trans = new CamelCase2UnderLine();
        $convert->setPropertyNameTrans($trans);
        self::assertEquals(spl_object_id($trans), spl_object_id($convert->getPropertyNameTrans()));
        $data = [
            "camel_meta" => "534",
            "key_word_log" => "7784jdr",
        ];
        $expect = NameChangePojo::builder(
            [
                "camelMeta" => $data["camel_meta"],
                "key_word_log" => $data["key_word_log"],
            ]
        );
        $result = $convert->convert($data, NameChangePojo::class);
        self::assertEquals($expect, $result);
    }
}

# end of file
